package com.egg.ylt.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;

import com.egg.ylt.R;
import com.egg.ylt.adapter.ADA_GrowthPhotosClassic;
import com.egg.ylt.pojo.GrowthPhotoClassicListEntity;
import com.egg.ylt.presenter.impl.GrowthStampPresenter;
import com.egg.ylt.view.IGrowthStampView;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.ruffian.library.widget.RTextView;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created By Dlx
 * on 2019/1/22
 */
public class ACT_GrowthStamp extends BaseActivity<GrowthStampPresenter> implements IGrowthStampView {


    private static final int IMAGE_PICKER = 100;
    @BindView(R.id.growth_diary_recyclerview)
    XRecyclerView growthDiaryRecyclerview;
    @BindView(R.id.no_pic_ll)
    LinearLayout noPicLl;
    @BindView(R.id.common_toolbar)
    Toolbar commonToolbar;
    @BindView(R.id.growth_stamp_addpic_tv)
    RTextView addpicTv;
    private ADA_GrowthPhotosClassic adapter;
    private boolean isFirstFlag = true;

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_growthdiary;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_growth_diary, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.take_photos:
                readyGo(ACT_WriteAndChosePhotos.class);
                break;
            case R.id.chose_photos:
                readyGo(ACT_WriteAndChosePhotos.class);
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void initViewsAndEvents() {
        setSupportActionBar(commonToolbar);
        commonToolbar.setTitle("成长印记");

        adapter = new ADA_GrowthPhotosClassic(this, mPresenter);
        growthDiaryRecyclerview.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        growthDiaryRecyclerview.setLoadingMoreEnabled(false);
        growthDiaryRecyclerview.setPullRefreshEnabled(false);
        growthDiaryRecyclerview.setAdapter(adapter);
        mPresenter.getGrowthStampPhotoClassicDatas();
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    public void showBusinessError(ErrorBean error) {

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (isFirstFlag) {
            isFirstFlag = false;
            return;
        }
        mPresenter.getGrowthStampPhotoClassicDatas();
    }

    @Override
    public void onPhotosClassicListSuccess(GrowthPhotoClassicListEntity result) {
        if (result.getList().size() == 0) {
            noPicLl.post(new Runnable() {
                @Override
                public void run() {
                    growthDiaryRecyclerview.setVisibility(View.GONE);
                    noPicLl.setVisibility(View.VISIBLE);
                }
            });
        } else {
            growthDiaryRecyclerview.post(new Runnable() {
                @Override
                public void run() {
                    growthDiaryRecyclerview.setVisibility(View.VISIBLE);
                    noPicLl.setVisibility(View.GONE);
                }
            });
            adapter.updateList(result.getList());
        }
    }

    @Override
    public void onPhotosClassicListFailed(String error) {

    }

    @Override
    public void showToast(String content) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.growth_stamp_addpic_tv)
    public void onViewClicked() {
        readyGo(ACT_WriteAndChosePhotos.class);
    }
}
